//
//  LBLoginVC.m
//  V-Learn
//
//  Created by Apple on 2018/12/25.
//  Copyright © 2018 yxk. All rights reserved.
//

#import "LBLoginVC.h"
#import "LBBoundingIponeVC.h"
#import "LoginView.h"
#import "UserModel.h"
#import "LBTabBarViewController.h"
#import "LBRegisterVC.h"
#import "LBForgetPasswordVC.h"
@interface LBLoginVC ()
@property (nonatomic,strong)LoginView * RootView;
@end
@implementation LBLoginVC

- (void)loadView{
    self.RootView = [[LoginView alloc] initWithFrame:LBScreenBounds];
    self.view = self.RootView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"登录";
    [self.RootView.RegisterButton addTarget:self action:@selector(GoRegister:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.RootView.ForgetPassWordBtn addTarget:self action:@selector(GoForgetPassWord:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.RootView.LoginButton addTarget:self action:@selector(clickLoginBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    
    if ([UserModel getUserModel]) {
//        [UMessage removeAlias:[UserModel getUserModel].username type:@"UMENGTEST" response:^(id  _Nullable responseObject, NSError * _Nullable error) {
//
//        }];
    }
    [self.RootView.VisitorButton addTarget:self action:@selector(clickVisitorBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    
}
- (void)clickVisitorBtn:(UIButton *)sender{
    [self.RootView LoginVisitorAction:^(BOOL isOK) {
        if (isOK) {
            if ([self.jumpType isEqualToString:@"1"]) {
                [self.navigationController popViewControllerAnimated:YES];
            }else{
                UIViewController * vc =  [UIApplication sharedApplication].keyWindow.rootViewController;
                if ([vc isKindOfClass:[LBNavigationController class]]) {
                    [UIApplication sharedApplication].keyWindow.rootViewController = [[LBTabBarViewController alloc] init];
                }else{
                    [UIApplication sharedApplication].keyWindow.rootViewController = [[LBTabBarViewController alloc] init];
                }
            }
            
        }
    }];
}
/**
 注册按钮,点击事件
 */
- (void)GoRegister:(UIButton *)btn{
    LBRegisterVC * vc = [[LBRegisterVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
/**
 忘记密码按钮,点击事件
 */
- (void)GoForgetPassWord:(UIButton *)btn{

    LBForgetPasswordVC * vc = [[LBForgetPasswordVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];

}

/**
 登录
 */
- (void)clickLoginBtn:(UIButton *)btn{
    
    [self.RootView LoginAction:^(BOOL isOK) {
        if (isOK) {
            if ([self.jumpType isEqualToString:@"1"]) {
                [self.navigationController popViewControllerAnimated:YES];
            }else{
                UIViewController * vc =  [UIApplication sharedApplication].keyWindow.rootViewController;
                if ([vc isKindOfClass:[LBNavigationController class]]) {
                    [UIApplication sharedApplication].keyWindow.rootViewController = [[LBTabBarViewController alloc] init];
                }else{
                    [UIApplication sharedApplication].keyWindow.rootViewController = [[LBTabBarViewController alloc] init];
                }
            }

        }
    }];
    
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([self.jumpType isEqualToString:@"1"]) {
        
    }else{
        [self.navigationController setNavigationBarHidden:YES animated:animated];
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if ([self.jumpType isEqualToString:@"1"]) {
        
    }else{
        [self.navigationController setNavigationBarHidden:NO animated:animated];
    }
    
}


@end
